package str

func buddyStrings(s string, goal string) bool {
	count := 0

	if len(s) != len(goal) {
		return false
	}

	if s == goal {
		bs := [26]bool{}
		for _, v := range s {
			if bs[v-'a'] {
				return true
			}
			bs[v-'a'] = true
		}
		return false
	}

	first, second := -1, -1

	for i := range s {
		if s[i] != goal[i] {
			count++
			if count > 2 {
				return false
			}

			if first == -1 {
				first = i
			} else if second == -1 {
				second = i
			}

		}
	}

	return count == 2 && s[first] == goal[second] && goal[first] == s[second]
}
